<template>
  <div class="shop">
    <div class="activity-wrap">
      <div class="activity">
        <div class="swiper mySwiper">
          <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="(item, index) in shopInfo.result" :key="index">
              <div class="day-text">Day {{ index + 1 }}</div>
              <div class="month-text">{{ getMonthAndDayFromTimestamp(item.startTime) }}</div>
              <!-- 已开始未选中 -->
              <div class="open-shop"
                v-if="item.endTime > shopInfo.timestamp && shopInfo.timestamp > item.startTime && index !== isActive"
                @click="selectMet(index)">
                <div class="head">
                  <img src="@/assets/images/activity/blackFriday/house.png" class="house" alt="">
                  <div class="shop-name">Pop up Shop {{ index + 1 }}</div>
                </div>
                <div class="bot">
                  <count-down :startTime="shopInfo.timestamp" :endTime="item.endTime"
                    labelText="Until it ends"></count-down>
                  <img src="@/assets/images/activity/blackFriday/dian.png" class="dian-img" alt="">
                </div>
              </div>
              <!-- 已开始已选中 -->
              <div class="on-open-sty"
                v-if="item.endTime > shopInfo.timestamp && shopInfo.timestamp > item.startTime && index === isActive">
                <div class="open-sel" @click="selectMet(index)">
                  <img src="@/assets/images/activity/blackFriday/border.png" class="border" alt="">
                  <div class="lock-img">
                    <div class="head">
                      <img src="@/assets/images/activity/blackFriday/house.png" class="house" alt="">
                      <div class="shop-name">Pop up Shop {{ index + 1 }}</div>
                    </div>
                    <div class="label-text">{{ $t('black.star_label1') }}</div>
                    <Rate disabled v-model="item.descNum" />
                    <div class="label-text">{{ $t('black.star_label2') }}</div>
                    <Rate disabled v-model="item.serviceNum" />
                    <div class="label-text">{{ $t('black.star_label3') }}</div>
                    <Rate disabled v-model="item.speedNum" />
                  </div>
                </div>
                <count-down style="margin-left: 32px;" :startTime="shopInfo.timestamp" :endTime="item.endTime"
                  labelText="Until it ends"></count-down>
              </div>
              <!-- 未开始且选中 -->
              <div class="un-open-sty"
                v-if="!(item.endTime > shopInfo.timestamp && shopInfo.timestamp > item.startTime) && index === isActive">
                <div class="lock-sel" @click="selectMet(index)">
                  <img src="@/assets/images/activity/blackFriday/border.png" class="border" alt="">
                  <img src="@/assets/images/activity/blackFriday/lock.png" class="lock-img" alt="">
                </div>
                <count-down v-if="item.endTime > shopInfo.timestamp" style="margin-left: 32px;"
                  :startTime="shopInfo.timestamp" :endTime="item.startTime" labelText="Will Open"></count-down>
              </div>
              <!-- 未开始未选中 -->
              <img
                v-if="!(item.endTime > shopInfo.timestamp && shopInfo.timestamp > item.startTime) && index !== isActive"
                src="@/assets/images/activity/blackFriday/small_lock.png" class="lock-img" @click="selectMet(index)"
                alt="">
            </div>
          </div>
        </div>
      </div>
      <div class="swiper-button-next"></div>
      <div class="swiper-button-prev"></div>
    </div>
  </div>
</template>
<script>
import Swiper from "swiper";
import "swiper/css/swiper.css";
import countDown from '@/views/main/activity/blackFriday/components/count-down.vue';
export default {
  components: { countDown },
  props: {
    shopInfo: Object,
    isActive: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
    }
  },
  created() {
    // setTimeout(() => {
    //   this.initSwiper();
    // }, 800)
  },
  methods: {
    getMonthAndDayFromTimestamp(timestamp) {
      const date = new Date(timestamp);
      const month = date.getMonth() + 1; // 月份是从0开始计数的，所以要加1
      const day = date.getDate();
      const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
      const shortMonthName = monthNames[month - 1].substring(0, 3);

      return `${shortMonthName}.${day}`;
    },
    // 初始化swiper
    initSwiper() {
      this.$nextTick(() => {
        this.currentSwiper = new Swiper(".mySwiper", {
          slidesPerView: 5,
          spaceBetween: 0,
          initialSlide: this.isActive,
          navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev",
          },
          pagination: {
            el: ".swiper-pagination",
            clickable: true,
          },
        });
      });
    },
    selectMet(index) {
      this.$emit('indexChange', index)
    }
  }
}
</script>
<style lang="less" scoped>
.shop {

  .activity-wrap {
    position: relative;
    margin: 0 100px;
    overflow: hidden;

    .activity {
      position: relative;
      z-index: 2;
      margin: 0 auto;
      overflow: hidden;
      margin-left: 40px;
      margin-right: 40px;

      .swiper {
        width: 100%;
        overflow: hidden;
      }

      .swiper-wrapper {
        display: flex;
        align-items: center;

        .swiper-slide {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;

          .day-text {
            font-family: Open Sans, Open Sans;
            font-weight: bold;
            font-size: 30px;
            line-height: 36px;
            background-image: linear-gradient(to bottom, #FF186B, #38e1ff);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            text-fill-color: transparent;
          }

          .month-text {
            font-family: Open Sans, Open Sans;
            font-weight: bold;
            font-size: 24px;
            line-height: 28px;
            background-image: linear-gradient(to bottom, #FF186B, #38e1ff);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            text-fill-color: transparent;
            margin-bottom: 4px;
          }

          .lock-img {
            width: 242px;
            height: 145px;
            cursor: pointer;
          }

          .open-shop {
            height: 145px;
            cursor: pointer;
            background-image: url('@/assets/images/activity/blackFriday/bg.png');
            background-repeat: no-repeat;
            background-size: 100% 100%;
            padding: 20px 20px 20px 16px;

            .head {
              display: flex;
              align-items: center;
              gap: 16px;
              margin-bottom: 16px;

              .house {
                width: 57px;
                height: 48px;
              }

              .shop-name {
                font-family: SF Compact, SF Compact;
                font-weight: 600;
                font-size: 20px;
                color: #FFFFFF;
                line-height: 37px;
              }
            }

            .bot {
              display: flex;
              align-items: end;
              gap: 32px;

              .dian-img {
                width: 74px;
                margin-bottom: 4px;
              }
            }
          }

          .open-sel {
            cursor: pointer;
            position: relative;

            .border {
              width: 304px;
            }

            .lock-img {
              width: 232px;
              height: 242px;
              background-image: url('@/assets/images/activity/blackFriday/bg.png');
              background-repeat: no-repeat;
              background-size: 100% 100%;
              padding: 20px 20px 20px 16px;
              position: absolute;
              top: 30px;
              left: 37px;

              .head {
                display: flex;
                align-items: center;
                gap: 16px;
                margin-bottom: 8px;

                .house {
                  width: 57px;
                  height: 48px;
                }

                .shop-name {
                  font-family: SF Compact, SF Compact;
                  font-weight: 600;
                  font-size: 20px;
                  color: #FFFFFF;
                  line-height: 37px;
                  text-wrap: nowrap;
                }
              }

              .label-text {
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 16px;
                color: #FFFFFF;
                line-height: 19px;
              }

              :deep(.ivu-rate) {
                .ivu-rate-star .ivu-rate-star-zero {
                  height: 14px;
                }
              }
            }
          }

          .un-open-sty {


            .lock-sel {
              cursor: pointer;
              position: relative;

              .border {
                width: 304px;
              }

              .lock-img {
                width: 220px;
                height: 242px;
                position: absolute;
                top: 30px;
                left: 42px;
              }
            }
          }
        }

      }
    }

    .swiper-button-next {
      // color: #aaaaaa;
      background-image: url(@/assets/images/home/right_arrow.svg);
      width: 68px;
      height: 68px;
      right: 0;

      &::after {
        content: none !important;
      }
    }

    .swiper-button-prev {
      background-image: url(@/assets/images/home/left_arrow.svg);
      width: 68px;
      height: 68px;
      left: 0;

      &::after {
        content: none !important;
      }
    }
  }
}
</style>
